import * as global_way from "./lib/ways/global.js";
import * as hints from "./lib/ways/hint.js";
import * as filters from "./lib/ways/filter.js";
import * as dates from "./lib/ways/date.js";
import * as verifys from "./lib/ways/verify.js";
import skip from "./lib/ways/skip.js";
import Http from './lib/ways/http.js'
import './static/icons/iconfont.css'
import themes from './static/theme.json'
const plugin = {
	install(Vue, options) {
		let systemInfo = uni.getSystemInfoSync()
		console.log(systemInfo,'systemInfo')
		let themeKey = systemInfo.theme || 'light'
		console.log(themeKey,'themeKey')
		let defaultColor = {
			main: '#2172FE',
			minor: '#FEE420',
			success: '#4cd964',
			pattern: '#fff',
			error:'',
			themeKey,
			theme:themes[themeKey]
		}
		if(options && options.themes){
			defaultColor.theme = Object.assign(defaultColor.theme,options.themes[themeKey]) 
		}
		Vue.prototype.$color = new Proxy(defaultColor,{
			get(target,key) {
				return target[key]
			},
			set(target,key,value) {
				target[key] =value
				return true
			}
		})
		Vue.prototype.$config = {
			baseUrl: ''
		}
		if (options && options.config) {
			Vue.prototype.$config = Object.assign(Vue.prototype.$config, options.config)
		}
		uni.$config = Vue.prototype.$config
		if (options && options.color) {
			Vue.prototype.$color= new Proxy(Object.assign(Vue.prototype.$color, options.color),{
				get(target,key){
					return target[key]
				},
				set(target,key,value){
					target[key] =value
					return true
				}
			})
		}
		if (options && options.inputStyle) {
			Vue.prototype.$inputStyle = options.inputStyle
		}
		if (options && options.footStyle) {
			Vue.prototype.$footStyle= new Proxy(options.footStyle,{
				get(target,key){
					return target[key]
				},
				set(target,key,value){
					target[key] =value
					return true
				}
			})
		}
		if(options && options.btnStyle ){
			Vue.prototype.$btnStyle = options.btnStyle
		}
		Object.keys(global_way).forEach((key) => {
			Vue.prototype[`$${key}`] = global_way[key];
		});
		Object.keys(hints).forEach((key) => {
			Vue.prototype[`$${key}`] = hints[key];
		});
		Object.keys(filters).forEach((key) => {
			Vue.filter(key, filters[key]);
		});
		Object.keys(skip).forEach((key) => {
			Vue.prototype[`$${key}`] = skip[key];
		});
		Object.keys(dates).forEach((key) => {
			Vue.prototype[`$${key}`] = dates[key];
		});
		Object.keys(verifys).forEach((key) => {
			Vue.prototype[`$${key}`] = verifys[key];
		});
		Vue.prototype.$bus = new Vue()
		Vue.prototype.$http = new Http({
			...Vue.prototype.$config
		})
		uni.$http = Vue.prototype.$http
		/**
		 * $setp 设置场景 是暗黑还是光明模式
		 * @param {string} themeKey light 为光明 dark 为黑暗
		 */
		Vue.prototype.$setP = (themeKey) => {
			Vue.prototype.$color.themeKey = themeKey
			Vue.prototype.$color.theme = themes[themeKey]
		}
		Vue.prototype.$setL = () => {

		}

	},
};
export default plugin;
